package com.shadt.sms.dao;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.shadt.core.dao.impl.BaseDaoImpl;
import com.shadt.sms.entity.MessageInfo;

/**
 * 短信数据访问层实现类
 * 
 * @author SongR
 * 
 */
@Repository
public class MessageInfoDaoImpl extends BaseDaoImpl<MessageInfo> implements
		MessageInfoDao {

	/**
	 * 实现获取所有未发送信息
	 */
	@SuppressWarnings("rawtypes")
	public List<MessageInfo> getAll(String sql) {
		List l = this.getJdbcTemplate().queryForList(sql);
		List<MessageInfo> mList = new ArrayList<MessageInfo>();
		Iterator it = l.iterator();
		if(l.size()>0){
			while(it.hasNext()){
				Map m = (Map)it.next();
				MessageInfo mi = new MessageInfo();
				mi.setSeqNo	   (m.get("SEQNO")    !=null?m.get("SEQNO"    ).toString():"");
				mi.setmPhone   (m.get("MPHONE")   !=null?m.get("MPHONE"   ).toString():"");
				mi.setBody	   (m.get("BODY")     !=null?m.get("BODY"     ).toString():"");
				mi.setMsgType  (m.get("MSGTYPE")  !=null?m.get("MSGTYPE"  ).toString():"");
				mi.setmStatus  (m.get("MSTATUS")  !=null?m.get("MSTATUS"  ).toString():"");
				mi.setsCount   (m.get("SCOUNT")   !=null?m.get("SCOUNT"   ).toString():"");
				mi.setSmsStatus(m.get("SMSSTATUS")!=null?m.get("SMSSTATUS").toString():"");
				mi.setSmsId	   (m.get("SMSID")	  !=null?m.get("SMSID"    ).toString():"");
				mi.setSmsResult(m.get("SMSRESULT")!=null?m.get("SMSRESULT").toString():"");
				mList.add(mi);
			}
		}
		return mList;
	}

	/**
	 * 实现修改消息
	 */
	public String updateMessage(String sql) {
		return this.getJdbcTemplate().update(sql)+"";
	}

}
